﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using DTO;
using BUS;

namespace MasterPageGroupF3
{
    public partial class NhaCungCapDangKyHCM : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            Session["idCity"] =2;
        }

        protected void btnDangKy_Click(object sender, EventArgs e)
        {
            CaptchaControl1.ValidateCaptcha(txtCaptcha.Text);
            if (CaptchaControl1.UserValidated)
            {
                PROVIDER proNew = new PROVIDER();
                if(PROVIDERBUS.TonTai_User(txtTenThanhVien.Text))
                {
                    Response.Write("<script language='javascript'>alert('User đã tồn tại.');</script>");
                    return;
                }

                proNew.NAME = txtTenCongTy.Text;
                proNew.USERNAME = txtTenThanhVien.Text;
                proNew.PASSWORD = txtMatKhau.Text;
                proNew.ADDRESS = txtDiaChi.Text;
                proNew.PHONE = txtDienThoai.Text;

                bool res = PROVIDERBUS.Add(proNew);
                if (res == true)
                {
                    Response.Write("<script language='javascript'>alert('Chúc mừng bạn " + txtTenThanhVien.Text + " đã đăng ký thành công.');</script>");
                }
                else
                {
                    Response.Write("<script language='javascript'>alert('Dang ky that bai.');</script>");
                }
            }
            else
            {
                Response.Write("<script language='javascript'>alert('Nhập sai mã xác nhận.');</script>");
            }  
        }
    }
}